package com.wp.land.config;


import com.wp.land.entity.Land;

import java.util.Objects;
import java.util.Optional;

/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2019/05/07
 * @Modified By:
 */

public class OptionalTest {

    public static void main(String[] args){
        Land user = null;

        user = Optional.ofNullable(user).orElseGet(() -> {
            System.out.println("12");
            return new Land("1",1);
        });
        System.out.println(user);
        Optional.ofNullable(user).ifPresent(u -> {
            System.out.println("123");
        });
        try {
//            check(null);
        }catch (NullPointerException e){

        }

        checkParams("xiaozhou",null);


    }

    /**
     * 直接返回
     * @param params
     */
    private static void checkParams(String ...params) {

        try {
            Objects.requireNonNull(params,"参数不能为空");
            for(String str:params){
                Objects.requireNonNull(str,"参数不能为空");
            }
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("123:"+e.getMessage());
        }
    }

    private static void check(String username) {
        Objects.requireNonNull(username,"用户名为空");
    }





}
